<template>
    <div class="post-comment">
        <van-field
            v-model="message"
            rows="2"
            autosize
            type="textarea"
            maxlength="50"
            placeholder="请输入留言"
            show-word-limit
        />
        <van-button :disabled="!message"  @click="onPost">发布</van-button>
    </div>
</template>
<script>
import { addComment } from '@/api/comment'
export default {
    data() {
        return {
            message:''
        }
    },
    methods: {
        async onPost(){
            this.$toast.loading({
                message:'发布中',
                forbidclick:true
            })
            const { data } = await addComment({
                art_id:this.articleId ? this.articleId.toString() : null,
                target:this.target.toString(),
                content:this.message
            })
            //console.log(data)
            //this.$emit('post-success',data.data.new_obj)

            this.$toast.success('发布成功')

            this.message = ""
        }
    },
    props:{
        target:{
            type:[Number,String,Object],
            required:true
        },
        articleId:{
            type:[Number,String,Object],
            default:null
        }
    }
}
</script>
<style lang="less" scoped>
.post-comment{
    display: flex;
    align-items: center;
    padding: 14px;
}
</style>